<template>
<!--
  - Copyright (C) 2018-2019
  - All rights reserved, Designed By www.joolun.com
  - 注意：
  - 本软件为www.joolun.com开发研制，项目使用请保留此说明
-->
<view class="cu-modal show" v-if="switchOn && wxUser && !wxUser.headimgUrl">
  <view class="cu-dialog">
    <view class="cu-bar bg-red justify-end">
      <view class="content">登录授权</view>
    </view>
    <view class="padding-xl">
      <view class="text-left">需要获取您的头像等信息，以便为您提供更好的服务</view>
      <button class="cu-btn text-green cuIcon-weixin lg" open-type="getUserInfo" @getuserinfo="agreeGetUser" lang="zh_CN">点击授权</button>
    </view>
  </view>
</view>
</template>

<script>
/**
 * Copyright (C) 2018-2019
 * All rights reserved, Designed By www.joolun.com
 * 注意：
 * 本软件为www.joolun.com开发研制，项目使用请保留此说明
 */
const app = getApp();
export default {data() {
return {
wxUser: null
};
}, 
props: {
  switchOn: {
    type: Boolean,
    default: true
  }
}, 
// 组件所在页面的生命周期函数
mounted: function () {
  this.setData({
    wxUser: app.globalData.wxUser
  });
}, 
methods: {
  agreeGetUser(e) {
    if (e.detail.errMsg == 'getUserInfo:ok') {
      app.globalData.api.wxUserSave(e.detail).then(res => {
        let wxUser = res.data;
        this.setData({
          wxUser: wxUser
        });
        app.globalData.wxUser = wxUser;
      });
    }
  }

}};
</script>
<style >


</style>